﻿using MediatR;
using SlaughterItem.Common.Domains.Setup;
using SlaughterItem.Common.Dtos;
using SlaughterItem.Common.Infrastructures.Interfaces;
using SlaughterItem.Enum;

namespace GetSlaughterItem.API.Application.Commands.Week02.BasicSettings
{
    public class WaitingQueryHandler : IRequestHandler<WaitingQueryCommand, Result>
    {
        /// <summary>
        /// 待宰圈设置仓储
        /// </summary>
        private readonly IBaseRepositoryGet<Waitings> waitingRepository;


        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="waitingRepository">待宰圈设置仓储</param>
        /// <param name="sectionsbaseRepository">部门仓储</param>
        public WaitingQueryHandler(IBaseRepositoryGet<Waitings> waitingRepository)
        {
            this.waitingRepository = waitingRepository;
            
        }

        /// <summary>
        /// 业务逻辑
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task<Result> Handle(WaitingQueryCommand request, CancellationToken cancellationToken)
        {
            var result = new Result() { Code = (int)CommonErrorCode.Success };

            try
            {
                var list = waitingRepository.GetAll().ToList();
                if (list != null)
                {
                    result.Code = (int)CommonErrorCode.Success;
                    result.Data = list;
                    result.Msg = "成功";
                }
            }
            catch (Exception)
            {

                throw;
            }

            return result;
        }
    }
}
